import 'package:flutter/material.dart';
import 'package:my_app/app/widgets/expandable_fab_widget.dart';

/// expandable_fab_page.dart
///
/// Created by fuchuanwei on Tue Feb 21 2023.
///
/// Description: 可展开Fab 页面
///
class ExpandableFabPage extends StatelessWidget {
  static const _actionTitles = ['Create Post', 'Upload Photo', 'Upload Video'];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('ExpandableFab'),
      ),
      floatingActionButton: ExpandableFabWidget(distance: 112.0, children: [
        ActionButton(
          onPressed: () => _showAction(context, 0),
          icon: const Icon(Icons.format_size),
        ),
        ActionButton(
          onPressed: () => _showAction(context, 1),
          icon: const Icon(Icons.insert_photo),
        ),
        ActionButton(
          onPressed: () => _showAction(context, 2),
          icon: const Icon(Icons.videocam),
        ),
      ]),
    );
  }

  void _showAction(BuildContext context, int index) {
    showDialog<void>(
      context: context,
      builder: (context) {
        return AlertDialog(
          content: Text(_actionTitles[index]),
          actions: [
            TextButton(
              onPressed: () => Navigator.of(context).pop(),
              child: const Text('CLOSE'),
            ),
          ],
        );
      },
    );
  }
}
